﻿

using ProtoBuf;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IotContract.Models.Plcs;
[ProtoContract]
public class PlcSCAddr
{
    /// <summary>
    /// 0 写入数据 1 入库 2 出库 3 移库  4 控制
    /// </summary>
    [ProtoMember(1)]
    public int ActionType { get; set; }
    /// <summary>
    /// 堆垛机编号
    /// </summary>
    [ProtoMember(2)]
    public int GroupNumber { get; set; }

    [ProtoMember(4)]
    public int JobNumber { get; set; }
    [ProtoMember(5)]
    [DefaultValue(0)]
    public int FromBank { get; set; }
    [ProtoMember(6)]
    [DefaultValue(0)]
    public int FromBay { get; set; }
    [ProtoMember(7)]
    [DefaultValue(0)]
    public int FromLevel { get; set; }
    [ProtoMember(8)]
    public int FromStation { get; set; }
    [ProtoMember(9)]
    [DefaultValue(0)]
    public int ToBank { get; set; }
    [ProtoMember(10)]
    [DefaultValue(0)]
    public int ToBay { get; set; }
    [ProtoMember(11)]
    [DefaultValue(0)]
    public int ToLevel { get; set; }
    [ProtoMember(12)]
    public int ToStation { get; set; }

    [ProtoMember(13)]
    [DefaultValue(0)]
    public int FromBank2 { get; set; }
    [ProtoMember(14)]
    [DefaultValue(0)]
    public int FromBay2 { get; set; }
    [ProtoMember(15)]
    [DefaultValue(0)]
    public int FromLevel2 { get; set; }
    [ProtoMember(16)]
    public int FromStation2 { get; set; }
    [ProtoMember(17)]
    [DefaultValue(0)]
    public int ToBank2 { get; set; }
    [ProtoMember(18)]
    [DefaultValue(0)]
    public int ToBay2 { get; set; }
    [ProtoMember(19)]
    [DefaultValue(0)]
    public int ToLevel2 { get; set; }
    [ProtoMember(20)]
    public int ToStation2 { get; set; }

    /// <summary>
    /// Bit  0：EMG急停； 1：Run 运行；2：Stop 停止；3：ERROR RESET 故障复位；4： Delete 删除
    /// </summary>
    [ProtoMember(21)]
    public int Command { get; set; }

    [ProtoMember(22)]
    public int JobNumber2 { get; set; }

    public override string ToString()
    {
        if (ActionType == 1)
        {
            return $"入库 FromStation:{FromStation},To : {ToBank}-{ToBay}-{ToLevel},入库 FromStation2:{FromStation2},To : {ToBank2}-{ToBay2}-{ToLevel2}";
        }
        else if (ActionType == 2)
        {
            return $"出库 From: {ToBank}-{ToBay}-{ToLevel},ToStation:{ToStation},出库 From2: {ToBank2}-{ToBay2}-{ToLevel2},ToStation:{ToStation2}";
        }
        else if (ActionType == 3)
        {
            return $" 移库 From: {FromBank}-{FromBay}-{FromLevel} To {ToBank}-{ToBay}-{ToLevel},移库 From2: {FromBank2}-{FromBay2}-{FromLevel2} To {ToBank2}-{ToBay2}-{ToLevel2}";
        }
        else
        {
            return base.ToString();
        }
    }

    /// <summary>
    /// 写入的时间，容错
    /// </summary>
    public DateTime? WriteTime { get; set; }

}
